<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Cookie;
use think\Db;
class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
    }

    public function changeLang() {
        $param = $this->request->param();
        Cookie::set('lang', $param['lang']);
        Cookie::set('think_var', $param['lang']);
        if (!empty($this->request->server('HTTP_REFERER'))) {
            $this->redirect($this->request->server('HTTP_REFERER'));
        } else {
            $this->redirect('/');
        }
    }

    public function index()
    {
       //banner
        $section['banner'] = $this->getContentByLang(Db::name('bannerlist')->where('status',1)->order('weigh','desc')->select());


        // 推荐产品
        $section['recommendProducts'] = $this->getContentByLang(Db::name('productslist')->where('tuiswitch',1)->order('weigh','desc')->limit(10)->select());

        //简介
        $section['jianjie'] = $this->getContentByLang(Db::name('danye')->where('id',20)->find());
        $section['gushi'] = $this->getContentByLang(Db::name('danye')->where('id',21)->find());

        $section['recommendList'] = $this->getContentByLang(Db::name('series')->where('tuijian_switch',1)->limit(2)->order('weigh', 'desc')->select());
        $section['recommendList2'] = $this->getContentByLang(Db::name('series')->where('jingdian_switch',1)->limit(3)->order('weigh', 'desc')->select());

        //推荐产品分类 和 列表
        $section['protype'] = $this->getContentByLang(Db::name('productstype')->where('switch',1)->order('weigh','desc')->limit(10)->select());
        foreach ($section['protype'] as $key => $value) {
            $section['protype'][$key]['list'] = $this->getContentByLang(Db::name('productslist')->where('tuiswitch',1)->where('productstype',$value['id'])->order('weigh','desc')->limit(4)->select());
        }

        // 新闻列表
        $section['news'] = $this->getContentByLang(Db::name('newslist')->where('tuiswitch', 1)->order('weigh','desc')->limit(3)->select());

        // 尊享体验
        $section['tiyan_list'] = $this->getContentByLang(Db::name('danye')->whereIn('id',[22,24,25,26])->order('weigh','desc')->select());

        $this->view->assign('section', $section);
        $this->view->assign('lanmu', 1);
        return $this->view->fetch();


    }


}
